package com.twohand.admin.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.twohand.admin.Entity.UserRole;
import com.twohand.admin.Mapper.UserRoleMapper;
import com.twohand.admin.Service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserRoleServiceImpl implements UserRoleService {
    @Autowired
    UserRoleMapper userRoleMapper;
    @Override
    public Boolean updateByUserId(UserRole userRole, Integer id) {
        LambdaQueryWrapper<UserRole> userRoleQueryWrapper = new LambdaQueryWrapper<>();
        //找到userid == id 的行
        userRoleQueryWrapper.eq(UserRole::getUserId,id);
        return userRoleMapper.update(userRole,userRoleQueryWrapper) > 0;
    }

    @Override
    public Boolean deleteByUserId(Integer id) {
        LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserRole::getUserId,id);
        return userRoleMapper.delete(lambdaQueryWrapper) > 0;
    }

    public Boolean insert(UserRole userRole){
        return userRoleMapper.insert(userRole) > 0;
    }
    @Override
    public Integer getRoleByUserId(Integer userId) {
        return userRoleMapper.getRoleIdByUserId(userId);
    }
}
